package com.liner.controller;

import com.liner.entity.ProductInfo;
import com.liner.service.ProductCategoryService;

import com.liner.service.ProductInfoService;
import com.liner.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 买家端 商品服务接口
 */

@RestController
@RequestMapping("/buyer/product")
@Api(tags = "买家端商品接口", description = "买家端 商品服务接口")
public class BuyerProductController {

    @Autowired
    private ProductCategoryService productCategoryService;

    @Autowired
    private ProductInfoService productInfoService;

    @ApiOperation("商品列表")
    @GetMapping("/list")
    public Result list() {
        return Result.ok(productCategoryService.buyerList());
    }

    @ApiOperation("根据 ID 查询商品价格")
    @ApiImplicitParam(name = "id", value = "商品ID")
    @GetMapping("/findPriceById/{id}")
    public BigDecimal findPriceById(@PathVariable("id") Integer id) {
        return productInfoService.findPriceById(id);
    }


    @ApiOperation("通过 ID 查询商品")
    @ApiImplicitParam(name = "id", value = "商品ID")
    @GetMapping("/findById/{id}")
    public ProductInfo findById(@PathVariable("id") Integer id) {
        return productInfoService.getById(id);
    }


    @ApiOperation("减库存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品ID"),
            @ApiImplicitParam(name = "quantity", value = "商品库存")
    })
    @PutMapping("/subStockById/{id}/{quantity}")
    public Boolean subStockById(@PathVariable("id") Integer id, @PathVariable("quantity") Integer quantity) {
        return productInfoService.subStockById(id, quantity);
    }

    @ApiOperation("加库存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品ID"),
            @ApiImplicitParam(name = "quantity", value = "商品库存")
    })
    @PutMapping("/addStockById/{id}/{quantity}")
    public Boolean addStockById(@PathVariable("id") Integer id, @PathVariable("quantity") Integer quantity) {
        return productInfoService.addStockById(id, quantity);
    }


}
